package com.vjwealth.android.nos.utils

import android.app.Activity
import java.util.*

/**
 * projectName KNOS
 * date 2017/9/26
 * description com.vjwealth.android.nos.utils
 */
class ActivityManagerUtils private constructor(){
    private object SingletonHolder{
        var INSTANCE = ActivityManagerUtils()
    }
    companion object {
        private var activityStack: Stack<Activity> = Stack()
        var instance  = SingletonHolder.INSTANCE
    }

    fun currentActivity(): Activity {
        var activity: Activity = activityStack.lastElement()
        return activity
    }

    fun popActivity(activity: Activity) {
        var activity = activity
        //在从自定义集合中取出当前Activity时，也进行了Activity的关闭操作
        activity.finish()
        activityStack?.remove(activity)
    }

    fun popAllActivity(){
        do {
            var activity = currentActivity()
            popActivity(activity)
        }while (activity != null)
    }

    fun pushActivity(activity: Activity){
        activityStack.add(activity)
    }

    fun isCurrentActivity(activity: Activity): Boolean{
        return activity == currentActivity()
    }
}